#!/bin/sh
#
# $OpenBSD: logstash.rc,v 1.5 2015/07/02 18:06:02 jasper Exp $

daemon_user="_logstash"
daemon="${TRUEPREFIX}/logstash/bin/logstash"
daemon_flags="--config ${SYSCONFDIR}/logstash/conf.d/ --log /var/log/logstash/logstash.log"

. /etc/rc.d/rc.subr

pexp="$(${LOCALBASE}/bin/javaPathHelper -c logstash).*logstash/runner.rb agent ${daemon_flags}"

rc_reload=NO

# Ensure _logstash can write to the logfile.
# XXX: Remove on upgrade.
rc_pre() {
	chown -R _logstash:_logstash /var/log/logstash
}

rc_start() {
	(${rcexec} "JAVA_HOME=\"$(${LOCALBASE}/bin/javaPathHelper -h logstash)\" \
		JAVA_OPTS=\"${JAVA_OPTS} -Djava.library.path=${LOCALBASE}/jruby/lib/jni/${JFFI_ARCH}\" \
		SINCEDB_DIR=\"/var/db/logstash\" \
	   	     ${daemon} ${daemon_flags}") &
}

rc_cmd $1
